//
//  EWHomeViewController.m
//  haveSomethingToEat
//
//  Created by 陈宁权 on 2017/4/8.
//  Copyright © 2017年 陈 宁权. All rights reserved.
//

#import "EWHomeViewController.h"
#import "HYPageView.h"
#import "EWReservationViewController.h"
#import "EWBreakfastViewController.h"

@interface EWHomeViewController ()
@property (nonatomic,strong) HYPageView *pageView;
@end

@implementation EWHomeViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _pageView = [[HYPageView alloc] initWithFrame:self.view.frame withTitles:@[@"订餐",@"早餐"] withViewControllers:@[@"EWReservationViewController",@"EWBreakfastViewController"] withParameters:nil];
    _pageView.isTranslucent = NO;
//    UIButton *addressBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    addressBtn.titleLabel.textColor = [UIColor whiteColor];
//    addressBtn.titleLabel.font = [UIFont systemFontOfSize:13];
//    addressBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
//    [addressBtn setImage:[[UIImage imageNamed:@"定位"] scaleToSize:CGSizeMake(15, 15)] forState:UIControlStateNormal];
//    [[BQLocationManager sharedManager] startUpdatingLocation];
//    if (![[BQLocationManager sharedManager] haveLocationAuth]) {
//        [addressBtn setTitle:@"请开启定位权限" forState:UIControlStateNormal];
//    }
//    else{
//        [self locationAtBtn:addressBtn];
//    }
//    _pageView.leftButton = addressBtn;
    [self.view addSubview:_pageView];
}

- (void)locationAtBtn:(UIButton *)addressBtn
{
    CLGeocoder *geoCoder = [[CLGeocoder alloc] init];
    [geoCoder reverseGeocodeLocation:[BQLocationManager sharedManager].location completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
        for (CLPlacemark *placemark in placemarks) {
            [addressBtn setTitle:[NSString stringWithFormat:@"%@",placemark.name] forState:UIControlStateNormal];
            CGSize size = [placemark.name sizeWithAttributes:@{NSFontAttributeName:addressBtn.titleLabel.font}];
            addressBtn.frame = CGRectMake(5, 35, size.width + 15, 20);
            addressBtn.transform = CGAffineTransformMakeScale(.9, .9);
            [_pageView.topTabView layoutIfNeeded];
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
